package test01;

/**
 * @author zhu
 * @date 2024-03-21
 */
public class Film {
    private int count;
    private String filmName;

    public Film() {
    }

    public Film(int count, String filmName) {
        this.count = count;
        this.filmName = filmName;
    }

    public void sell(){
        while (this.count >= 1){
            synchronized (this){
                if (this.count > 0){
                    System.out.print(Thread.currentThread().getName() + "出售《" + this.filmName + "》");
                    System.out.println("，卖出了第" + this.count + "张电影票");
                    this.count--;
                }
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
